package com.mingqijia.gassafety.shared.utils.commonUtils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mingqijia.gassafety.db.entity.auth.BaseEntry;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
public class PageUtil<T> {

    /**
     * 当前页码
     */
    @JsonProperty(value = "page")
    private int page = 1;

    /**
     * 每页记录数
     */
    @JsonProperty(value = "page_size")
    private int pageSize = 10;

    /**
     * 总记录条数
     */
    @JsonProperty(value = "total")
    private long total;

    /**
     * 返回数据集合
     */
    @JsonProperty(value = "list")
    private List<T> list;

    /**
     * 返回数据集合
     */
    private List<PageColumns> columns = new ArrayList<>();

    public static <E extends BaseEntry, T> PageUtil<T> init(IPage<E> results, List<T> data) {
        return new PageUtil<>((int)results.getCurrent(), (int)results.getSize(), results.getTotal(), data, new ArrayList<>());
    }


    public PageUtil(int page,int pageSize,long total,List<T> list){
        this.page = page;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        this.columns = new ArrayList<>();
    }

    public PageUtil(int page,int pageSize,long total,List<T> list,List<PageColumns> columns){
        this.page = page;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        this.columns = columns;
    }

    public PageUtil(){
    }
}

